package com.czl.module_user.adapter

import android.text.Editable
import android.text.TextWatcher
import com.blankj.utilcode.util.StringUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.czl.base.binding.command.BindingCommand
import com.czl.base.binding.command.BindingConsumer
import com.czl.base.data.bean.ScoreListBean
import com.czl.base.util.ToastHelper.showNormalToast
import com.czl.module_user.R
import com.czl.module_user.databinding.ItemScoreBinding
import com.czl.module_user.fragment.ScoreListFragment

/**
 *
 * @Description:
 * @Author: XCH
 * @CreateDate: 2021/12/10 11:38
 */
class ScoreAdapter(private val fragment: ScoreListFragment) :
    BaseQuickAdapter<ScoreListBean.Data, BaseDataBindingHolder<ItemScoreBinding>>(
        R.layout.item_score
    ) {

    override fun convert(
        holder: BaseDataBindingHolder<ItemScoreBinding>,
        item: ScoreListBean.Data
    ) {
        holder.dataBinding?.apply {
            data = item
            adapter = this@ScoreAdapter
            executePendingBindings()
        }
    }

    val onAppraiseClick: BindingCommand<Any> = BindingCommand(BindingConsumer {
        if (it is ScoreListBean.Data) {
            if (StringUtils.isTrimEmpty(it.etContent)){
                showNormalToast("请输入回复内容")
                return@BindingConsumer
            }
            fragment.viewModel.replyEvaluate(it.id.toString(),it.etContent)
        }
    })

    val onSwitchClick: BindingCommand<Any> = BindingCommand(BindingConsumer {
        if (it is ScoreListBean.Data) {
            it.etVisible = !it.etVisible
            notifyDataSetChanged()
        }
    })
}